package com.spbdx.studyspringboot.duty_chain.chain;

import com.spbdx.studyspringboot.duty_chain.entity.Product;

/**
 * @Author: fan
 * @CreateTime 2025/1/1 21:34
 * @Description 责任链
 * @Version 1.0
 */
public abstract class IHandler<T,R> {

    protected IHandler<T,R> nextHandler;

    public void setNext(IHandler<T,R> nextHandler) {
        this.nextHandler = nextHandler;
    }

    public boolean hasNextHandler() {
        return nextHandler != null;
    }

    public R handle(T t) {
        if(hasNextHandler()){
            nextHandler.handle(t);
        }

        return null;
    }
}
